
<template>
    <div class="container">
        <b-card-new>
            <b-query-form-new ref="bForm" :data="formData" :form="dataForm.query" @search="handleSearch"></b-query-form-new>
            <b-query-table ref="bTable" :init-columns="initColumns()" :data-form="dataForm" :handleList="handleList"></b-query-table>
        </b-card-new>
    </div>
</template>
<script>
import mixinPageHeight from "@/mixinPageHeight"
export default {
    mixins:[mixinPageHeight],
    data() {
        return {
            formData:[
                { typeCode: "input", title: "搜索内容", name: "search" },
            ],
            dataForm:{
                url: "api/ads/list",
                query:{
                    search: "", // 搜索内容
                }
            },
            
            // 按钮
            handleList: [
                {
                    name: '添加',
                    btnCode: '',
                    btnClick: () =>  this.handleLinkTo('', 0)
                }
            ]
        }
    },
    created() {
       
    },
    methods:{
        initColumns() {
            return [
                { title:"序号", valueName: "rn" },
                { title:"广告标题", valueName: "title" },
                { title:"广告图片", valueName: "image_url" },
                { title:"开始时间", valueName: "start_time" },
                { title:"结束时间", valueName: "end_time" },
                { title:"操作", fixed: 'right', width: 220, customRander: (row) => (
                    <BTableOperation list={
                        [
                            { name: '编辑', btnCode: '10', btnClick: () => this.handleLinkTo(row.id)},
                            { name: '删除', btnCode: '9', btnClick: () => this.handleDel(row)},
                        ]
                        }></BTableOperation>
                    ),
                }
            ]
        },
        // 添加编辑
        handleLinkTo(id){
            this.$router.push({
                path: '/banner/detail',
                query: {
                    id: id
                }
            })
        },
        // 删除
        handleDel(row){
            this.$common.bconfirm("确定删除？", "提示").then(res => {
                this.$api.setting.adsRemoveds({id:row.id}).then(res => {
                    this.$message.success('删除成功')
                    this.$refs.bTable.reload();
                })
            })
        }
    }
}
</script>
<style lang="scss" scoped>
.d-flex{
    display: flex;
    align-items: center;
}
</style>